<template>
  <u-gap height="1" bgColor="rgba(138,138,138,0.35)"> </u-gap>
  <view style=" ">
    <view style="padding: 30rpx 30rpx 150rpx 30rpx">
      <u-textarea
          v-model="introduction"
          placeholder="介绍喜好、个性"
          :auto-height="true"
          type="text"
          border="none" :clearable="true" :showWordLimit="true" maxlength="50"></u-textarea>
    </view>
    <u-gap height="1" bgColor="rgba(138,138,138,0.35)"> </u-gap>
    <view style="display: flex;align-items: center;
    justify-content: center;padding: 55vh 30vw 20vh 20vw;">
      <u-button  shape="circle" size="large" @tap="alterUserIntroduction"
                 :disabled="introduction.trim() == '' || introduction == origin" color="#ea4757">保存</u-button>
    </view>
  </view>
</template>

<script>
import user from "@/store/user";
import {alterFrontUserIntro, alterFrontUsername} from "@/api/user";

export default {
  data() {
    return {
      introduction:'',
      origin: '',
    };
  },
  onLoad(options) {
    console.log(options.introduction)
    if(options.introduction != '' || options.introduction != undefined || options.introduction != null ){
      this.introduction = options.introduction
      this.origin = options.introduction
    }
  },
  methods: {
    async alterUserIntroduction(){
      if(this.introduction === this.origin){
        uni.showToast({
          title: '不能与原来的相同哦',
          icon: 'none'
        })
        return
      }
      const res = await alterFrontUserIntro(this.introduction)
      if(res.code == 200){
        uni.showToast({
          title: '修改成功',
          icon: 'none'
        })
        setTimeout(() => {
          uni.navigateBack({
            delta: 1
          })
        }, 1000)
      }else {
        uni.showToast({
          title: '修改失败',
          icon: 'none',
          position: 'bottom'
        })
      }
    }
  },
}
</script>

<style lang="scss">

</style>
